from api import log
from api.api_factory import ApiFactory
import requests

from tool import html_parser


class TestTenderList:
    def setup(self):
        self.session = requests.session()
        self.api = ApiFactory(self.session)

    def teardown(self):
        self.session.close()

    def test01_tender_list(self):
        try:
            # 1、获取图片验证码接口
            self.api.get_register_login().api_img_code(123123)
            # 2、获取短信验证码接口
            self.api.get_register_login().api_phone_code("13600001111",8888)
            # 3、注册接口
            self.api.get_register_login().api_register("13600001111","test123","8888",666666)
            # 4、登录接口
            self.api.get_register_login().api_login()
            # 5、认证接口
            self.api.get_approve().api_approve()
            # 6、后台开户接口
            result = self.api.get_approve().api_trust()
            # 7、三方开户
            data = html_parser(result)
            result = self.session.post(url=data[0], data=data[1])
            log.info("三方开户接口执行结果为：{}".format(result.text))
            # 8、充值验证码接口
            self.api.get_recharge().api_img_code(88881123)
            # 9、后台充值接口
            result = self.api.get_recharge().api_recharge()
            # 10、三方充值接口
            data = html_parser(result)
            result = self.session.post(url=data[0], data=data[1])
            log.info("三方充值接口执行结果为：{}".format(result.text))
            # 11、后台投资接口
            result = self.api.get_tender().api_tender(100)
            # 12、三方投资接口
            data = html_parser(result)
            result = self.session.post(url=data[0], data=data[1])
            log.info("三方投资接口执行结果为：{}".format(result.text))
        except Exception as e:
            log.error(e)
            raise
